<!DOCTYPE html>
<html>
  <head>
      <meta charset="utf-8">
      <title></title>
      <meta name="renderer" content="webkit">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
      <link rel="stylesheet" href="/usercp/layui/css/layui.css" media="all">
      <link rel="stylesheet" href="/usercp/style/admin.css" media="all">
  </head>
  <body>
    <div class="m-site-framebody">
      <div class="layui-form" lay-filter="setting">
        <div class="layui-form-item">
          <label class="layui-form-label">站点名称</label>
          <div class="layui-input-inline">
            <input type="text" name="name" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">所属客户</label>
          <div class="layui-inline" style="width: 148px;">
                <select name="custom_id" lay-filter="custom_id" required lay-verify="required" lay-search>
                </select>
            </div>
        </div>
        <!-- <div class="layui-form-item">
          <label class="layui-form-label">宣传图片</label>
          <div class="layui-input-inline">
            <button type="button" class="layui-btn" id="logo">
              <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
          </div>
          <div class="layui-form-mid layui-word-aux">宣传图片，显示在小程序的“公司简介”页面</div>
          <input type="hidden" name="logo" id="logo">
          <div class="layui-input-inline" id="img_box">
             
          </div>
        </div> -->

        <div class="layui-form-item">
          <label class="layui-form-label">宣传图片</label>
          <div class="layui-input-inline">
            <input name="logo" lay-verify="required" id="logo" placeholder="图片地址" value="" class="layui-input">
          </div>
          <div class="layui-input-inline layui-btn-container" style="width: auto;">
            <button type="button" class="layui-btn layui-btn-primary" id="LAY_logoUpload">
              <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <button class="layui-btn layui-btn-primary" layadmin-event="logoPreview">查看图片</button >
          </div>
          <div class="layui-form-mid layui-word-aux">宣传图片，显示在小程序的“公司简介”页面</div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">联系电话</label>
          <div class="layui-input-inline">
            <input type="text" name="phone" placeholder="请输入联系电话" autocomplete="off" class="layui-input">
          </div>
          <div class="layui-form-mid layui-word-aux">联系电话，显示在小程序的“公司简介”页面</div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">站点介绍</label>
            <div class="layui-input-inline" style="margin-bottom: 20px; width: 550px;">
              <textarea id="add_content" lay-verify="content" name="desc" style="display: none;"></textarea>
            </div>
          <div class="layui-form-mid layui-word-aux">站点介绍，显示在小程序的“公司简介”页面</div>
        </div>
        <div class="layui-form-item layui-hide">
          <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
        </div>  
      </div>
    </div>
    <style>
      html {
        background-color: #fff;
      }
      .m-site-framebody {
        padding: 10px 15px;
      }
      .m-site-framebody-header {
        margin-bottom: 20px;
        padding-bottom: 10px;
        font-size: 14px;
        border-bottom: 1px solid #e6e6e6;
      }
      .layui-table, .layui-table-view {
        margin: 0;
      }
    </style>
      <script src="/usercp/layui/layui.js"></script>
    <script>
    layui.config({
      base: '/usercp/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index', 'site/edit']);

    layui.use(['form','upload','layedit'], function(){
        var form = layui.form;
        var $ = layui.$;
        var site_id = getQueryString('site_id');
        var formdata = {};
        var row = window.parent.ooob;
        var upload = layui.upload;
        var img = '';
        var layedit = layui.layedit;
        layedit.set({
            //暴露layupload参数设置接口 --详细查看layupload参数说明
            uploadImage: {
                url: '/usercp/upload/upload_editor',
                accept: 'image',
                acceptMime: 'image/*',
                exts: 'jpg|png|gif|bmp|jpeg',
                size: '10240'
            }
            , uploadVideo: {
                url: '/usercp/upload/upload_editor',
                accept: 'video',
                acceptMime: 'video/*',
                exts: 'mp4|flv|avi|rm|rmvb',
                size: '20480'
            }
            //右键删除图片/视频时的回调参数，post到后台删除服务器文件等操作，
            //传递参数：
            //图片： imgpath --图片路径
            //视频： filepath --视频路径 imgpath --封面路径
            // , calldel: {
            //     url: '/Attachment/DeleteFile'
            // }
            //开发者模式 --默认为false
            , devmode: true
            //插入代码设置
            , codeConfig: {
                hide: true,  //是否显示编码语言选择框
                default: 'javascript' //hide为true时的默认语言格式
            }
            , tool: [
                'code', 'strong', 'italic', 'underline', 'del', 'addhr', '|', 'fontFomatt', 'colorpicker', 'face'
                , '|', 'left', 'center', 'right', '|', 'link', 'unlink', 'image_alt', 'video', 'anchors'
                , '|','table', 'fullScreen'
            ]
        });
        var index = layedit.build('add_content',{
          height: 400 //设置编辑器高度
        });
        form.verify({
            content: function(value) { 
                return layedit.sync(index);
            }
        });
        var uploadInst = upload.render({
          elem: '#logo' //绑定元素
          ,url: '/usercp/upload/upload' //上传接口
          ,done: function(res){
            //上传完毕回调
            upload_path = res.data;
            img = '<img src="'+ res.data +'" width="38px" heigth="38px" />';
            $('#img_box').html(img);
            form.val('setting',{
              'logo':res.data
            })
          }
          ,error: function(){
            //请求异常回调
            layer.msg(res.msg, {
              offset: '50px'
              ,icon: 2
              ,anim: 6
              ,time: 1000
            }, function(){});
          }
        });
        
        $.get('/usercp/site/custom_lists', {}, function (data) {
                var $html = "";
                if(data.data != null){
                    $.each(data.data, function (index, item) {
                      $html += "<option value='" + item.current_id + "'>" + item.username + "</option>";
                    });
                  $("select[name='custom_id']").append($html);
                  //append后必须从新渲染
                  form.render('select');
               }
               form.val('setting',{
                'name':row.name,
                'token':row.token,
                'desc':row.desc,
                'site_id':row.id,
                'custom_id':row.custom_id,
                'phone':row.phone,
                'logo':row.logo
              })
              layedit.setContent(index, row.desc, false);
              site_id = row.id;
        })        

        function getQueryString(name) { 
          var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
          var r = window.location.search.substr(1).match(reg); 
          if (r != null) return unescape(r[2]); return null; 
        } 
    });
    </script>
  </body>
</html>
